/*
 * @FilePath: \undefinedc:\Users\sxjct\.leetcode\91.解码方法.cpp
 * @Brief: 
 * @Version: 1.0
 * @Date: 2021-03-08 11:10:26
 * @Author: tianyiyi
 * @Copyright: Copyright@tianyiyi
 * @LastEditors: Mr.Tian
 * @LastEditTime: 2021-04-22 15:23:44
 */
/*
 * @lc app=leetcode.cn id=91 lang=cpp
 *
 * [91] 解码方法
 */

// @lc code=start
class Solution {
public:
    int numDecodings(string s) {
        int n = s.size();
        
        vector<int> dp(n+1);
        dp[0] = 1;
        for(int i = 1 ; i <= n ; i++)
        {
            if(s[i - 1] != '0')
            {
                dp[i] += dp[i - 1];
            }
            if(i > 1 && s[i-2]!='0' && ((s[i - 1] - '0') + (s[i - 2] - '0' )*10) <= 26)
            {
                dp[i] += dp[i - 2];
            }
        }
        return dp[n];
    }
};
// @lc code=end

